import Vue from 'vue'
import Vuex from 'vuex'
import { setStore,getStore } from '@/config/mUtils'
Vue.use(Vuex)

const state = {
	headerShow: true,
	user: null,
	menus:[],
}

const getters = {
	getHeaderShow(state) {
		return state.headerShow;
	},
	getUser(state){
		if(state.user == null){
			let user = getStore('user');
			if(user == "undefined"){
				return "";
			}else{
				return JSON.parse(getStore('user'));
			}
		}
		return state.user;
	},
	getMenu(state){
		
		if(state.menus.length == 0){
			
			let menus = getStore('menus');
			if(menus == "undefined"){
				return "";
			}else{
				return JSON.parse(getStore('menus'));
			}
		}
		return state.menus;
	},
}
const mutations = {
	changeHeaderShow(state, headerShow) {
		state.headerShow = headerShow;
	},
	saveUser(state, user) {
		state.user = user;
		//保存登录用户对象
		setStore('user', user);
	},
	saveMenu(state, menus) {
		state.menus = menus;
		//保存登录用户对象
		setStore('menus', menus);
	},
}

const actions = {
	
}

export default new Vuex.Store({
	getters,
	state,
	actions,
	mutations,
})